import http from '../utils/axios-init'
import qs from '../utils/qs'
// 请求表格统计数据
function getPagedata(data) {

    return new Promise((resolve, reject) => {
        http.post("/trademark/proPublic/selByCondition", data)
            .then((res) => {
                resolve(res)
            }).catch(error => {
                reject(error)
            });
    })
}
// 请求图表统计数据
function getChartData(data) {
    return new Promise((resolve, reject) => {
        http.post('/trademark/proPublic/selByConditionTree', data).then(res => {
            resolve(res)
        }).catch(error => {
            reject(error)
        })
    })
}
// 导出Excel
function outExcelgetdata(data) {
    return new Promise((resolve, reject) => {
        http.post('/trademark/proPublic/generation', data, {
            responseType: 'blob' //服务器返回的数据类型
        }).then((res) => {
            resolve(res)
        }).catch(error => {
            reject(error)
        })

    })
}

// 导出年度报表Excel
function excelProvince(data) {
    return new Promise((resolve, reject) => {
        http.post('/trademark/report/excelProvince', data, {
            responseType: 'blob', //服务器返回的数据类型
            // headers: {
            //   "Content-Type": "application/javascript; charset=UTF-8",
            // }
        }).then((res) => {
            resolve(res)
        }).catch(error => {
            reject(error)
        })
    })
}
// 导出商标受理窗口业务受理量汇总表Excel
function excelNetwork(data) {
    //   console.log("asdasd");
    return new Promise((resolve, reject) => {
        http.post('/trademark/report/excelNetwork', data, {
            responseType: 'blob', //服务器返回的数据类型
            headers: {
                "Content-Type": "application/json; charset=UTF-8",
            }
        }).then((res) => {
            resolve(res)
        }).catch(error => {
            reject(error)

        })
    })
}
// 获取网点
function getnet() {
    return new Promise((resolve, reject) => {
        http.get('/trademark/system/dept/findDept').then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}

// 新增批次
function addbatch(data) {
    return new Promise((resolve, reject) => {
        http.post('/trademark/certificate/insert', data).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}
// 查询证书批次
function getbathdata(data) {
    // console.log(data)
    return new Promise((resolve, reject) => {
        http.get('/trademark/certificate/findAll', {
            params: data
        }).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })

}
// 检索查询批次
function getTypedo(data) {
    return new Promise((resolve, reject) => {
        http.post('/trademark/certificate/findByType', data).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}
// 导出证书列表Excel
function outExcelgetdataids(data) {
    return new Promise((resolve, reject) => {
        http.post('/trademark/procertificate/export', data, {
            responseType: 'blob' //服务器返回的数据类型
        }).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}


function deletebatch(data) {
    return new Promise((resolve, reject) => {
        http.delete('/trademark/certificate/deleteByBatchNumber?' + qs(data, "batchNumber")).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}
// 证书已发放

function getissued(data, pagedto) {

    return new Promise((resolve, reject) => {
        let certificateDto = {
            "proCertificate": data,
            "pageDto": pagedto
        }
        http.post('/trademark/procertificate/findByLikeAllPage', JSON.stringify(certificateDto)).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}

function getList(data, pagedto) {

    return new Promise((resolve, reject) => {
        let outletStatisticsDto = {
            "outletStatistics": data,
            "pageDto": pagedto
        }
        http.post('/trademark/outletStatistics/findLikeOutletStatistics', JSON.stringify(outletStatisticsDto)).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}
function getExport(data) {

    return new Promise((resolve, reject) => {
        let outletStatisticsDto = {
            "outletStatistics": data,
           
        }
        http.post('/trademark/outletStatistics/export', JSON.stringify(outletStatisticsDto),{
            responseType: 'blob', //服务器返回的数据类型
            headers: {
                "Content-Type": "application/json; charset=UTF-8",
            }
        }).then(res => {
            
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}

// 证书未发放
function getnotued(data, pagedto) {
    return new Promise((resolve, reject) => {
        let certificateDto = {
            "proCertificate": data,
            "pageDto": pagedto
        }
        http.post('/trademark/procertificate/findByLikeAllPage', JSON.stringify(certificateDto)).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}
// 证书发放处理
function grantbook(regNum) {
    return new Promise((resolve, reject) => {
        http.post('/trademark/procertificate/updProCertificateState?regNum=' + regNum).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}

// 根据id删除单个证书
function deleteone(regNum) {
    return new Promise((resolve, reject) => {
        http.post('/trademark/procertificate/deleteByRegNum/' + regNum).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}
// 批量删除证书
function batchdeletebook(data) {
    return new Promise((resolve, reject) => {
        http.post('/trademark/proAppoint/delCredProAppointBatchById?' + qs(data, "ids"), ).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}
// 证书多条件查询
function batchmoresearch(data, pagedto) {

    // batchmoresearchDate(data)
    let certificateDto = {
            "proCertificate": data,
            "pageDto": pagedto
        }
        console.log(certificateDto);
        //   console.log(certificateDto);
    return new Promise((resolve, reject) => {
        http.post('/trademark/procertificate/findByLikeAllPage', JSON.stringify(certificateDto)).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}
// 保存证书
function scaveBatch(data) {
    return new Promise((resolve, reject) => {
        http.post('/trademark/procertificate/addProCertificate', data).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}
// 获取回文统计信息
function returnInfo(data) {
    return new Promise((resolve, reject) => {
        http.get('/trademark/statistics/getPalindrome', {
            params: data
        }).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })

}
// 检索回文信息
function getPalindromesearching(data) {
    return new Promise((resolve, reject) => {
        http.post('/trademark/statistics/getPalindromeByType', data).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}

// 获取用户资料统计信息
function getuserInfodata(data) {
    return new Promise((resolve, reject) => {
        http.get('/trademark/statistics/getProfile', {
            params: data
        }).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}

// 检索用户信息
function getuserromesearching(data) {
    return new Promise((resolve, reject) => {
        http.post('/trademark/statistics/getProfileByType', data).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}
// 回文信息统计excel
function outplalindromeExcel(data) {
    return new Promise((resolve, reject) => {
        http.post('/trademark/statistics/export', data, {
            responseType: 'blob' //服务器返回的数据类型
        }).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}
// 修改未发放
function updatadata(data) {
    // console.log(data)
    return new Promise((resolve, reject) => {
        http.post('/trademark/procertificate/updProCertificate', data).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}

function userinfoexcel(data) {
    return new Promise((resolve, reject) => {
        http.post('/trademark/statistics/exportUser', data, {
            responseType: 'blob' //服务器返回的数据类型
        }).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}

// 证书管理多条件查询日期格式转换
function batchmoresearchDate(data) {
    if (data.regStartTime == 'NaN-NaN-NaN' || data.regStartTime == 'NaN-0NaN-0NaN 0NaN:0NaN:0NaN') {

        data.regStartTime = null
    } else {
        data.regStartTime = dateTime(data.regStartTime)
    }
    if (data.grantTime == 'NaN-0NaN-0NaN 0NaN:0NaN:0NaN' || data.grantTime == 'NaN-NaN-NaN') {
        data.grantTime = null
    } else {
        data.grantTime = dateTime(data.grantTime)
    }
}

// 日期格式转换
function dateTime(time) {
    var date = new Date(time);
    var year = date.getFullYear();
    /* 在日期格式中，月份是从0开始的，因此要加0
     * 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
     * */
    var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
    var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
    var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
    var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
    // 拼接
    return year + "-" + month + "-" + day;
}
export {
    getPagedata,
    outExcelgetdata,
    getChartData,
    getnet,
    addbatch,
    getbathdata,
    getTypedo,
    deletebatch,
    getissued,
    getnotued,
    grantbook,
    deleteone,
    batchdeletebook,
    batchmoresearch,
    outExcelgetdataids,
    returnInfo,
    outplalindromeExcel,
    getuserInfodata,
    excelNetwork,
    getPalindromesearching,
    updatadata,
    excelProvince,
    getuserromesearching,
    userinfoexcel,
    scaveBatch,
    getList,
    getExport
}